-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add backward compatibility for missing kind #214
Conversation
28d2d00
to
ec492f3
Compare
@@ -425,6 +425,7 @@ def api | |||
def load_entities | |||
@entities = {} | |||
fetch_entities['resources'].each do |resource| | |||
resource = Kubeclient::Common::Compatibility31.compatible_resource(resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zakiva shouldn't you do this only if resource['kind'].nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I checked it inside the method: https://github.com/abonas/kubeclient/pull/214/files#diff-f1f5af126b7e6ff600fcc39decd74abfR64 thought it would be nicer to hide it.
Should I check it here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zakiva it's late here so don't assume that this works (or makes sense 😊)... but I would have expected something as:
fetch_entities['resources'].each do |resource|
next if resource['name'].include?('/')
resource['kind'] = Compatibility31.resource_kind(resource['name']) if resource['kind'].nil?
...
Instead of nil?
you can also think to use empty?
(I always forget the nits... anyway it would be nice to catch also when it's an empty string).
@moolitayer please check if the above makes sense.
For example, the check next if resource['name'].include?('/')
is fully valid and working on 3.1 as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm good with that (.nil? since empty comes from rails) I'd definitely like to see a backward compatibility test.
@zakiva take a look at test/json/core_api_resource_list.json and it's use all over. You would probably want to rename it to core_api_resource_list_v13.json and add a core_api_resource_list_v11.json that you can test in a new file.
@zakiva please link this on the BZ as well |
module Kubeclient | ||
module Common | ||
# Backward compatibility for 3.1 | ||
class Compatibility31 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure regarding the naming here (and the file name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In pure ruby it is not really important, in rails this would need to be named compatibility31.rb for you class name. I think we should change the class name to Compatibility11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the context of a "kubernetes client", 3.1 is unclear. OpenShiftEnterprise31 would be more explicit (is it OCP now? I think it was OSE when it was 3.1)
But I don't think we're 100% clear when it happened, and why downstream 3.1 was affected and origin 1.1 wasn't.
I tried to find when "kind" fields were added in openshift git log but gave up.
I compared upstream/downstream master config yaml — nothing jumped out either.
And I haven't tried kubernetes 1.1 (non-openshift) at all! (trying to compile it now, no luck so far)
Perhaps some neutral name like MissingKindCompatibility + a comment explaining we saw this happening in OSE 3.1?
That way if we learn more we won't need to rename the file/class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moolitayer @simon3z I would like to go with @cben's suggestion MissingKindCompatibility
since we are not sure yet that kind is missing in k8s 1.1, are you OK with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
@zakiva I asked to add a note in the readme about supported kubernetes versions. ps We need to make sure future manageiq code is aware of that, and uses other apis only if available. |
ec492f3
to
2b8e077
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice brute force approach! 🎯 🔨
I assume you tested this on OSE 3.1 and things actually work? (e.g. ManageIQ refresh)
} | ||
|
||
def self.compatible_resource(resource) | ||
resource['kind'].nil? ? resource.merge!('kind' => MAPPING[resource['name']]) : resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer non-mutating merge
over merge!
. Or just:
resource['kind'] ||= MAPPING[resource['name']]
Or what simon3z suggested in calling function.
module Kubeclient | ||
module Common | ||
# Backward compatibility for 3.1 | ||
class Compatibility31 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the context of a "kubernetes client", 3.1 is unclear. OpenShiftEnterprise31 would be more explicit (is it OCP now? I think it was OSE when it was 3.1)
But I don't think we're 100% clear when it happened, and why downstream 3.1 was affected and origin 1.1 wasn't.
I tried to find when "kind" fields were added in openshift git log but gave up.
I compared upstream/downstream master config yaml — nothing jumped out either.
And I haven't tried kubernetes 1.1 (non-openshift) at all! (trying to compile it now, no luck so far)
Perhaps some neutral name like MissingKindCompatibility + a comment explaining we saw this happening in OSE 3.1?
That way if we learn more we won't need to rename the file/class.
@@ -198,6 +198,9 @@ You can also load your JSONified config in from an ENV variable (e.g. `KUBE_CONF | |||
``` | |||
Kubeclient::Config.new(JSON.parse(ENV['KUBE_CONFIG']), nil) | |||
``` | |||
###Supported kubernetes versions | |||
|
|||
For 1.1 only the core api is supported, apis/extensions are supported in later versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could in principle extend the mapping, right? It's just we don't yet need them?
Saying 1.1 is not precise, when I tried Origin 1.1 I did get kind
fields. See my comment on naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that in order to support apis/extensions it will be more than just extend the mapping,
@moolitayer is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be in the mapping AFAIK. Since we have to manually test, review and add tests for everything we support I would rather we scope this change only for core api|oapi.
We would also need to check if we have cases of different apis using same entities.
- we are supporting v1 only right? please state that here
- can you figure out with @cben which is the currect k8s version to use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 'v1'. @cben the point is that we know that for OSE 3.1 ( - kubernetes v1.1.0-origin ) kind is missing, so anyway we can't guarantee support for 1.1 and that's what I have mentioned in the readme.
35612b9
to
9be2bc3
Compare
@moolitayer added tests, please take another look. |
LGTM |
@@ -198,6 +198,9 @@ You can also load your JSONified config in from an ENV variable (e.g. `KUBE_CONF | |||
``` | |||
Kubeclient::Config.new(JSON.parse(ENV['KUBE_CONFIG']), nil) | |||
``` | |||
###Supported kubernetes versions | |||
|
|||
For 1.1 only the core api v1 is supported, apis/extensions are supported in later versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apis/extensions is only one group api(the only one in 1.1 but not in later versions) please change to
For 1.1 only the core api v1 is supported, all api groups are supported in later versions.
.to_return(body: open_test_file('core_api_resource_list_without_kind.json'), | ||
status: 200) | ||
|
||
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentheses please
.to_return(body: open_test_file('core_oapi_resource_list_without_kind.json'), | ||
status: 200) | ||
|
||
client = Kubeclient::Client.new 'http://localhost:8080/oapi/', 'v1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentheses please
LGTM 👍 cc @simon3z |
Nice! 👍 |
When the MissingKindCompatability class was introduced in ManageIQ#214, it didn't properly singularize SecurityContextConstraint as the kind in the MAPPING. When this gets loaded in the test/test_resource_list_without_kind.rb, it tries defining the `get_security_context_constraints` twice: * Once for the list action * Once for the record This means that you would not have both a singluar and plural method name for the entities.method_names list, and they both would be plural.
When the MissingKindCompatability class was introduced in ManageIQ#214, it the mapping has a plural form of the kind, instead of the singular form like most of the other entries. When this gets loaded in the test/test_resource_list_without_kind.rb, it tries defining the `get_security_context_constraints` twice: * Once for the list action * Once for the record This means that you would not have both a singluar and plural method name for the entities.method_names list, and they both would be plural. To fix, do something similar to what was done for the `Endpoints` entry, which is to have a rule for it in `Kubeclient::Common#parse_definition`
Adding static mapping for resources in order to keep compatibility for Openshift 3.1 (kubernetes v1.1.0-origin).
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1387614
@simon3z @moolitayer @cben @zeari